cc.Class({
    extends: cc.Component,

    properties: {
        frame:cc.SpriteFrame,
    },
    // use this for initialization
    onLoad: function () {
        cc.log(this.frame.name);
        var sprite = this.node.getComponent(cc.Sprite);
        if(!sprite) return;

        cc.loader.loadRes(this.frame.name, cc.SpriteFrame, function (err, spriteFrame) {
                if(err) return;
                // var sprite = this.node.getComponent(cc.Sprite);
                // sprite.spriteFrame = spriteFrame;

                var onSpriteFrameLoaded = function (event) {
                    sprite.spriteFrame = spriteFrame;
                    sprite.node.color = cc.Color.WHITE;
                }.bind(this);

                if (spriteFrame.textureLoaded()) {
                    sprite.spriteFrame = spriteFrame;
                }
                else {
                    spriteFrame.once('load', onSpriteFrameLoaded);
                    spriteFrame.ensureLoadTexture();
                }
            }.bind(this)
        );
    }
});
